package com.canbot.u05.activity.agenda.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import com.canbot.u05.R
import com.canbot.u05.activity.agenda.bean.AgendaPosBean
import com.canbot.u05.activity.agenda.interfaces.IAgendaTypeLisenter

/**
 * @author yinxiaowei
 * @date 2019/5/31
 */
class AgendaPosAdapter(private val dataList: List<AgendaPosBean>, private val context: Context, private val iAgendaTypeLisenter: IAgendaTypeLisenter?) : RecyclerView.Adapter<AgendaPosAdapter.AgendaTypeViewHolder>() {
    private val inflater: LayoutInflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): AgendaTypeViewHolder {
        val inflate = inflater.inflate(R.layout.activity_agenda_work_pos_item, viewGroup, false)
        return AgendaTypeViewHolder(inflate)
    }

    override fun onBindViewHolder(agendaTypeViewHolder: AgendaTypeViewHolder, i: Int) {
        val agendaTypeBean = dataList[i]
        agendaTypeViewHolder.btnPos.text = agendaTypeBean.name
        agendaTypeViewHolder.btnPos.isSelected = agendaTypeBean.isSelect
        agendaTypeViewHolder.btnPos.setOnClickListener {
            iAgendaTypeLisenter?.onSelect(i)
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    inner class AgendaTypeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        internal var btnPos = itemView.findViewById<Button>(R.id.btn_pos);
    }
}
